<?php
/**
 * Created by PhpStorm.
 * User: lee
 * Date: 12/7/18
 * Time: 4:39 PM
 */

$domainName = 'ws.coincap.io';
$port = 443;
$ssl = true;
$cli = new \Swoole\Http\Client($domainName, $port, $ssl);
//$cli->setHeaders(array('User-Agent' => 'swoole-http-client',
//    'Host' =>  $domainName,
//    'Accept' => 'text/html,application/xhtml+xml,application/xml',
//    'Accept-Encoding' => 'gzip',
//));
//$cli->setCookies(array('test' => 'value'));
$cli->set([
    'websocket_mask' => true,
    'ssl_host_name' => 'ws.coincap.io',
]);
$cli->setHeaders([
    'Host' =>  'ws.coincap.io',
    'UserAgent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) snap Chromium/70.0.3538.110 Chrome/70.0.3538.110 Safari/537.36'
]);
$cli->on('message', function ($_cli, $frame) {
    echo '123123';
    echo $frame;
});

$cli->upgrade('/prices?assets=bitcoin', function ($cli) {
    echo $cli->body;
    $cli->push('hello world');
});